package xyz.yuzegod.megawalls.classes.normal.pirate;

import net.minecraft.server.v1_8_R3.Entity;
import net.minecraft.server.v1_8_R3.World;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import xyz.yuzegod.megawalls.MegaWalls;
import xyz.yuzegod.megawalls.classes.Classes;
import xyz.yuzegod.megawalls.classes.Skill;
import xyz.yuzegod.megawalls.game.GamePlayer;
import xyz.yuzegod.megawalls.nms.CustomBat;
import xyz.yuzegod.megawalls.stats.KitStatsContainer;
import xyz.yuzegod.megawalls.util.EntityTypes;

import java.util.ArrayList;
import java.util.List;

public class SecondSkill extends Skill
{
    public SecondSkill(final Classes classes) {
        super("愤怒的小鸟", classes);
    }
    
    @Override
    public int maxedLevel() {
        return 3;
    }
    
    @Override
    public double getAttribute(final int level) {
        switch (level) {
            case 1: {
                return 50.0;
            }
            case 2: {
                return 40.0;
            }
            case 3: {
                return 30.0;
            }
            default: {
                return 50.0;
            }
        }
    }
    
    @Override
    public List<String> getInfo(final int level) {
        final List<String> lore = new ArrayList<String>();
        if (level == 1) {
            lore.add(" §8▪ §7每§a" + this.getAttribute(level) + "§7秒召唤一只鹦鹉。当你受到");
            lore.add("   §7攻击时,你的鹦鹉会在敌人处爆");
            lore.add("   §7炸并造成2点真实伤害。");
            return lore;
        }
        lore.add(" §8▪ §7每§8" + this.getAttribute(level - 1) + " ➜ §a" + this.getAttribute(level) + "§7秒召唤一只鹦鹉。当你受到");
        lore.add("   §7攻击时,你的鹦鹉会在敌人处爆");
        lore.add("   §7炸并造成2点真实伤害。");
        return lore;
    }
    
    @Override
    public void upgrade(final GamePlayer gamePlayer) {
        final KitStatsContainer kitStats = gamePlayer.getPlayerStats().getKitStats(this.getClasses());
        kitStats.addSkill2Level();
    }
    
    @Override
    public int getPlayerLevel(final GamePlayer gamePlayer) {
        return gamePlayer.getPlayerStats().getKitStats(this.getClasses()).getSkill2Level();
    }
    
    @Override
    public boolean use(final GamePlayer gamePlayer, final KitStatsContainer kitStats) {
        if (Pirate.skill2Cooldown.getOrDefault(gamePlayer, (int)this.getAttribute(kitStats.getSkill2Level())) > 0 || !MegaWalls.getInstance().getGame().isWallsFall()) {
            return false;
        }
        final CustomBat bat = new CustomBat((World)((CraftWorld)Bukkit.getWorld("world")).getHandle());
        EntityTypes.spawnEntity((Entity)bat, gamePlayer.getPlayer().getLocation());
        bat.setGamePlayer(gamePlayer);
        Pirate.skill2Cooldown.put(gamePlayer, (int)this.getAttribute(this.getPlayerLevel(gamePlayer)));
        return true;
    }
}
